home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbnets1a / protect.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-07  |  10.4 KB  |  302 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form NetStat 
  4.    AutoRedraw      =   -1  'True
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   "vbNetStat"
  7.    ClientHeight    =   3960
  8.    ClientLeft      =   45
  9.    ClientTop       =   405
  10.    ClientWidth     =   9375
  11.    ClipControls    =   0   'False
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3960
  16.    ScaleWidth      =   9375
  17.    StartUpPosition =   1  'CenterOwner
  18.    Begin MSComctlLib.ListView NSview 
  19.       Height          =   3360
  20.       Left            =   0
  21.       TabIndex        =   3
  22.       Top             =   360
  23.       Width           =   9375
  24.       _ExtentX        =   16536
  25.       _ExtentY        =   5927
  26.       View            =   3
  27.       MultiSelect     =   -1  'True
  28.       LabelWrap       =   -1  'True
  29.       HideSelection   =   -1  'True
  30.       FullRowSelect   =   -1  'True
  31.       _Version        =   393217
  32.       ForeColor       =   -2147483640
  33.       BackColor       =   -2147483643
  34.       BorderStyle     =   1
  35.       Appearance      =   1
  36.       NumItems        =   4
  37.       BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  38.          Text            =   "Protocol"
  39.          Object.Width           =   1411
  40.       EndProperty
  41.       BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  42.          SubItemIndex    =   1
  43.          Text            =   "Local Address:port"
  44.          Object.Width           =   6174
  45.       EndProperty
  46.       BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  47.          SubItemIndex    =   2
  48.          Text            =   "Remote Address:port"
  49.          Object.Width           =   6174
  50.       EndProperty
  51.       BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  52.          SubItemIndex    =   3
  53.          Text            =   "State"
  54.          Object.Width           =   2469
  55.       EndProperty
  56.    End
  57.    Begin MSComctlLib.Toolbar Toolbar1 
  58.       Align           =   1  'Align Top
  59.       Height          =   360
  60.       Left            =   0
  61.       TabIndex        =   1
  62.       Top             =   0
  63.       Width           =   9375
  64.       _ExtentX        =   16536
  65.       _ExtentY        =   635
  66.       ButtonWidth     =   609
  67.       ButtonHeight    =   582
  68.       AllowCustomize  =   0   'False
  69.       Wrappable       =   0   'False
  70.       Appearance      =   1
  71.       Style           =   1
  72.       ImageList       =   "Images"
  73.       _Version        =   393216
  74.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  75.          NumButtons      =   6
  76.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  77.             Key             =   "Quit"
  78.             Description     =   "Quit"
  79.             Object.ToolTipText     =   "Quit"
  80.             ImageIndex      =   6
  81.          EndProperty
  82.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  83.             Style           =   3
  84.          EndProperty
  85.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  86.             Key             =   "Refresh"
  87.             Description     =   "Refresh"
  88.             Object.ToolTipText     =   "Refresh"
  89.             ImageIndex      =   9
  90.          EndProperty
  91.          BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  92.             Key             =   "Print"
  93.             Description     =   "Print"
  94.             Object.ToolTipText     =   "Print"
  95.             ImageIndex      =   7
  96.          EndProperty
  97.          BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  98.             Style           =   3
  99.          EndProperty
  100.          BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  101.             Key             =   "Help"
  102.             Description     =   "Help"
  103.             Object.ToolTipText     =   "Help"
  104.             ImageIndex      =   4
  105.          EndProperty
  106.       EndProperty
  107.       Begin VB.PictureBox Picture1 
  108.          Height          =   0
  109.          Left            =   0
  110.          ScaleHeight     =   0
  111.          ScaleWidth      =   0
  112.          TabIndex        =   2
  113.          Top             =   0
  114.          Width           =   0
  115.       End
  116.    End
  117.    Begin MSComctlLib.ImageList Images 
  118.       Left            =   7920
  119.       Top             =   3120
  120.       _ExtentX        =   1005
  121.       _ExtentY        =   1005
  122.       BackColor       =   -2147483643
  123.       ImageWidth      =   16
  124.       ImageHeight     =   16
  125.       MaskColor       =   12632256
  126.       _Version        =   393216
  127.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  128.          NumListImages   =   9
  129.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  130.             Picture         =   "Protect.frx":0000
  131.             Key             =   "Proc"
  132.          EndProperty
  133.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  134.             Picture         =   "Protect.frx":059C
  135.             Key             =   "Watch"
  136.          EndProperty
  137.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  138.             Picture         =   "Protect.frx":09F0
  139.             Key             =   "Kill"
  140.          EndProperty
  141.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  142.             Picture         =   "Protect.frx":0E44
  143.             Key             =   "Help"
  144.          EndProperty
  145.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  146.             Picture         =   "Protect.frx":1598
  147.             Key             =   "About"
  148.          EndProperty
  149.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  150.             Picture         =   "Protect.frx":19EC
  151.             Key             =   "Exit"
  152.          EndProperty
  153.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  154.             Picture         =   "Protect.frx":1E40
  155.             Key             =   "Print"
  156.          EndProperty
  157.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  158.             Picture         =   "Protect.frx":1F54
  159.             Key             =   "Reg"
  160.          EndProperty
  161.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  162.             Picture         =   "Protect.frx":20B0
  163.             Key             =   "Refresh"
  164.          EndProperty
  165.       EndProperty
  166.    End
  167.    Begin MSComctlLib.StatusBar SBar 
  168.       Align           =   2  'Align Bottom
  169.       Height          =   255
  170.       Left            =   0
  171.       TabIndex        =   0
  172.       Top             =   3705
  173.       Width           =   9375
  174.       _ExtentX        =   16536
  175.       _ExtentY        =   450
  176.       _Version        =   393216
  177.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  178.          NumPanels       =   3
  179.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  180.             Alignment       =   1
  181.             Object.Width           =   13053
  182.             MinWidth        =   13053
  183.          EndProperty
  184.          BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  185.             Style           =   5
  186.             Object.Width           =   1587
  187.             MinWidth        =   1587
  188.             TextSave        =   "11:23 PM"
  189.          EndProperty
  190.          BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  191.             Style           =   6
  192.             Alignment       =   1
  193.             Object.Width           =   1940
  194.             MinWidth        =   1940
  195.             TextSave        =   "10/07/1999"
  196.          EndProperty
  197.       EndProperty
  198.    End
  199.    Begin VB.Menu m_procoptions 
  200.       Caption         =   "Options"
  201.       Visible         =   0   'False
  202.       Begin VB.Menu m_KillProc 
  203.          Caption         =   "Kill Process"
  204.       End
  205.       Begin VB.Menu sbar0 
  206.          Caption         =   "-"
  207.       End
  208.       Begin VB.Menu mProcinfo 
  209.          Caption         =   "Process Info"
  210.       End
  211.    End
  212.    Begin VB.Menu m_regoptions 
  213.       Caption         =   "Options"
  214.       Visible         =   0   'False
  215.       Begin VB.Menu m_RegRemove 
  216.          Caption         =   "Remove Entry"
  217.       End
  218.    End
  219. Attribute VB_Name = "NetStat"
  220. Attribute VB_GlobalNameSpace = False
  221. Attribute VB_Creatable = False
  222. Attribute VB_PredeclaredId = True
  223. Attribute VB_Exposed = False
  224. Option Explicit
  225. Private Sub Form_Load()
  226.   RefreshNS
  227. End Sub
  228. Private Sub RefreshNS()
  229. Dim Item As ListItem
  230. Dim ln As Integer, x As Integer
  231. Dim Fn As String, D1 As String
  232. Dim LStr As String
  233. Dim FileNum As Integer
  234. Dim FileLength As Long
  235.   NSview.ListItems.Clear
  236.   Fn = App.Path & "\netstat.txt"
  237.   ShellAndWait "c:\command.com /c c:\windows\netstat.exe -a >" & Fn
  238.   FileNum = FreeFile
  239.   Open Fn For Input As FileNum  ' Open file for input.
  240.   FileLength = LOF(FileNum)
  241.   If FileLength > 10 Then
  242.     For ln = 1 To 4
  243.       Input #FileNum, LStr  ' Read data
  244.     Next
  245.     Do While Not EOF(FileNum)  ' Loop until end of file.
  246.       Input #FileNum, LStr  ' Read data
  247.       Set Item = NSview.ListItems.Add()
  248.       Item.Text = GetNxtWord(LStr)
  249.       For x = 1 To 3
  250.         D1 = GetNxtWord(LStr)
  251.         Item.SubItems(x) = D1
  252.       Next
  253.     Loop
  254.   End If
  255.   Close #FileNum  ' Close file.
  256. End Sub
  257. Function GetNxtWord(ByRef S As String) As String
  258. Dim i As Integer, x As Integer, s1 As String, s2 As String
  259.     s1 = S
  260.     i = InStr(s1, " ")
  261.     If (i > 1) Then
  262.       s2 = Left(s1, i - 1)
  263.       S = Right(s1, (Len(s1) - i))
  264.       If Left(s2, 1) <> " " Then
  265.         GetNxtWord = s2
  266.         Exit Do
  267.       End If
  268.     ElseIf (i = 0) Then
  269.       GetNxtWord = s1
  270.       S = ""
  271.       Exit Do
  272.     Else
  273.       S = Right(s1, (Len(s1) - i))
  274.     End If
  275.   Loop
  276. End Function
  277. Private Sub Form_Terminate()
  278.   Unload Me
  279. End Sub
  280. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  281.   Select Case Button.Key
  282.     Case "Refresh"
  283.       RefreshNS
  284.     Case "Quit"
  285.       Unload Me
  286.   End Select
  287. End Sub
  288. Public Sub ShellAndWait(ByVal CommandLine As String)
  289. Dim ReturnValue As Long
  290. Dim Start As STARTUPINFO
  291. Dim Process As PROCESS_INFORMATION
  292. ' Initialize the STARTUPINFO structure:
  293.   Start.cb = Len(Start)
  294.   Start.dwFlags = STARTF_USESHOWWINDOW
  295.   Start.wShowWindow = SW_HIDE
  296.   ' Start the shelled application:
  297.   ReturnValue = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, Process)
  298.   ' Wait for the shelled application to finish
  299.   ReturnValue = WaitForSingleObject(Process.hProcess, INFINITE)
  300.   CloseHandle Process.hProcess
  301. End Sub
  302.